package com.ydj.app.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ydj.app.entity.CmsAccount;
import com.ydj.app.protocol.http.cms.*;
import com.ydj.app.service.KolService;
import com.ydj.framework.exception.CommonException;
import com.ydj.framework.filter.ExtHttpServletResponse;
import com.ydj.framework.protocol.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.io.IOException;

@RestController
@RequestMapping("/cms/kol")
@Api(tags = "CMS-KOL")
public class CmsKolController {
    @Autowired
    private KolService kolService;

    @ResponseBody
    @ApiOperation(value = "列表")
    @ApiOperationSupport(order = 10)
    @PostMapping(value = "/list")
    public JsonResult<CmsKolListRes> list(@RequestBody @Validated CmsKolListReq req, @ApiIgnore CmsAccount account) throws CommonException {
        CmsKolListRes res = kolService.cmsList(req, account);
        return JsonResult.success(res);
    }

    @ResponseBody
    @ApiOperation(value = "新增")
    @ApiOperationSupport(order = 20)
    @PostMapping(value = "/create")
    public JsonResult<?> create(@RequestBody @Validated CmsKolCreateReq req, @ApiIgnore CmsAccount account) throws CommonException {
        CmsKolCreateRes res = kolService.cmsCreate(req, account);
        return JsonResult.success(res);
    }

    @ResponseBody
    @ApiOperation(value = "修改")
    @ApiOperationSupport(order = 30)
    @PostMapping(value = "/update")
    public JsonResult<?> update(@RequestBody @Validated CmsKolUpdateReq req, @ApiIgnore CmsAccount account) throws CommonException {
        kolService.cmsUpdate(req, account);
        return JsonResult.success();
    }

    @ResponseBody
    @ApiOperation(value = "删除")
    @ApiOperationSupport(order = 40)
    @PostMapping(value = "/delete")
    public JsonResult<?> delete(@RequestBody @Validated CmsKolDeleteReq req, @ApiIgnore CmsAccount account) throws CommonException {
        kolService.cmsDelete(req, account);
        return JsonResult.success();
    }

    @ResponseBody
    @ApiOperation(value = "结算")
    @ApiOperationSupport(order = 50)
    @PostMapping(value = "/settle")
    public JsonResult<?> settle(@RequestBody @Validated CmsKolSettleReq req, @ApiIgnore CmsAccount account) throws CommonException {
        kolService.cmsSettle(req, account);
        return JsonResult.success();
    }

    @ApiOperation(value = "导出Excel")
    @ApiOperationSupport(order = 60)
    @PostMapping(value = "/exportExcel")
    public JsonResult<?> exportExcel(@ApiIgnore ExtHttpServletResponse response, @RequestBody @Validated CmsKolExportExcelReq req, @ApiIgnore CmsAccount account) throws CommonException, IOException {
        kolService.cmsExportExcel(response, req, account);
        return JsonResult.success();
    }
}